import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
import UnoCSS from 'unocss/vite'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import { viteMockServe } from 'vite-plugin-mock'

export default defineConfig(({ command }) => {
  return {
    plugins: [
      vue(),
      UnoCSS(),
      AutoImport({
        imports: ['vue', 'vue-router', 'pinia'],
        resolvers: [ElementPlusResolver()]
      }),
      Components({
        resolvers: [ElementPlusResolver()]
      }),
      // Mock 数据配置
      viteMockServe({
        mockPath: 'mock',  // mock 文件目录
        enable: command === 'serve',  // 只在开发环境启用
        logger: true  // 显示 mock 请求日志
      })
    ],
    resolve: {
      alias: {
        '@': path.resolve(__dirname, 'src')
      }
    },
    server: {
      port: 3000,
      proxy: {
        // 如果需要代理真实后端 API，可以在这里配置
        // '/real-api': {
        //   target: 'http://your-backend-url',
        //   changeOrigin: true,
        //   rewrite: (path) => path.replace(/^\/real-api/, '')
        // }
      }
    }
  }
})